import { type NextRequest, NextResponse } from "next/server"

export async function GET(request: NextRequest) {
  try {
    const searchParams = request.nextUrl.searchParams
    const userId = searchParams.get("userId")
    const page = searchParams.get("page") ? Number.parseInt(searchParams.get("page")!) : 1
    const limit = searchParams.get("limit") ? Number.parseInt(searchParams.get("limit")!) : 20

    // 模拟数据
    const mvs = Array.from({ length: 12 }, (_, i) => ({
      id: i + 1,
      title: `MV Title ${i + 1}`,
      artist: `Artist ${(i % 5) + 1}`,
      cover: `/placeholder.svg?height=300&width=500&text=MV+${i + 1}`,
      duration: 180 + i * 30,
      views: (1000 + i * 100).toLocaleString(),
      url: `/api/stream?mvId=${i + 1}`,
    }))

    return NextResponse.json({
      data: mvs,
      pagination: {
        page,
        limit,
        total: 40,
        totalPages: Math.ceil(40 / limit),
      },
    })
  } catch (error) {
    console.error("Error fetching user liked MVs:", error)
    return NextResponse.json({ error: "Failed to fetch user liked MVs" }, { status: 500 })
  }
}

export async function POST(request: NextRequest) {
  try {
    const body = await request.json()
    const { mvId } = body

    return NextResponse.json({
      success: true,
      message: `MV ${mvId} added to favorites`,
    })
  } catch (error) {
    console.error("Error adding MV to favorites:", error)
    return NextResponse.json({ error: "Failed to add MV to favorites" }, { status: 500 })
  }
}

export async function DELETE(request: NextRequest) {
  try {
    const body = await request.json()
    const { mvId } = body

    return NextResponse.json({
      success: true,
      message: `MV ${mvId} removed from favorites`,
    })
  } catch (error) {
    console.error("Error removing MV from favorites:", error)
    return NextResponse.json({ error: "Failed to remove MV from favorites" }, { status: 500 })
  }
}

